package br.com.loja.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import br.com.loja.Bean.CadastroBean;
import br.com.loja.Conexao.Conexao;

public class CadastroDao {

	Connection con = null;

	public void inserirClietne(CadastroBean cadastro) throws SQLException {
		con = Conexao.getConexao();
		String sql = "INSERT INTO loja VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

		PreparedStatement stmt = con.prepareStatement(sql);
		stmt.setInt(1, cadastro.getId());
		stmt.setString(2, cadastro.getNome());
		stmt.setString(3, cadastro.getSobrenome());
		stmt.setString(4, cadastro.getDtNascimento());
		stmt.setString(5, cadastro.getRg());
		stmt.setString(6, cadastro.getCpf());
		stmt.setString(7, cadastro.getCep());
		stmt.setString(8, cadastro.getRua());
		stmt.setInt(9, cadastro.getNumero());
		stmt.setString(10, cadastro.getBairro());
		stmt.setString(11, cadastro.getCidade());
		stmt.setString(12, cadastro.getEstado());
		stmt.setString(13, cadastro.getTelResidencial());
		stmt.setString(14, cadastro.getTelComercial());
		stmt.setString(15, cadastro.getCelular());
		stmt.setString(16, cadastro.getEmail());
		stmt.setString(17, cadastro.getObs());

		stmt.execute();
		Conexao.closePreparedStatement(stmt);
		Conexao.closeConnection(con);

	}

	public List<CadastroBean> lista() throws SQLException {

		con = Conexao.getConexao();
		String sql = "select * from loja";
		PreparedStatement stmt = con.prepareStatement(sql);
		ResultSet rs = stmt.executeQuery();
		List<CadastroBean> lista = new ArrayList<CadastroBean>();
		while (rs.next()) {
			CadastroBean cad = new CadastroBean();
			cad.setId(rs.getInt("id"));
			cad.setNome(rs.getString("nome"));
			cad.setSobrenome(rs.getString("sobrenome"));
			cad.setDtNascimento(rs.getString("dtnascimento"));
			cad.setRg(rs.getString("rg"));
			cad.setCpf(rs.getString("cpf"));
			cad.setCep(rs.getString("cep"));
			cad.setRua(rs.getString("rua"));
			cad.setNumero(rs.getInt("numero"));
			cad.setBairro(rs.getString("bairro"));
			cad.setCidade(rs.getString("cidade"));
			cad.setEstado(rs.getString("estado"));
			cad.setTelResidencial(rs.getString("telResidencial"));
			cad.setTelComercial(rs.getString("telcomercial"));
			cad.setCelular(rs.getString("celular"));
			cad.setEmail(rs.getString("email"));
			cad.setObs(rs.getString("obs"));
			lista.add(cad);

		}

		return lista;

	}
}
